#include <dbg.h>

#include <cassert>

using namespace std;

class Solution {
public:
    long long countSubarrays(vector<int>& nums, long long k) {
        long long res = 0;
        long long sum = 0;
        int left = 0;
        for (int right = 0; right < nums.size(); right++) {
            sum += nums[right];
            while (sum * (right - left + 1) >= k) {
                sum -= nums[left];
                ++left;
            }
            res += right - left + 1;
        }
        return res;
    }
};

int main() {
    Solution s;

    vector<int> nums1{2, 1, 4, 3, 5};
    vector<int> nums2{1, 1, 1};

    long long k1 = 10;
    long long k2 = 5;

    assert(s.countSubarrays(nums1, k1) == 6);
    assert(s.countSubarrays(nums2, k2) == 5);

    return 0;
}